package com.lj.api.v1.c;

import com.lj.api.common.Result;
import com.lj.mcore.entity.Area;
import com.lj.mcore.entity.GoodsBrand;
import com.lj.mcore.service.IAddressService;
import com.lj.mcore.service.IAreaService;
import com.lj.mcore.tools.AreaTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/c")
public class AddressConotroller {

    @Autowired
    IAddressService addressService;

    @Autowired
    IAreaService areaService;

    @RequestMapping("/addressList")
    public String addressList(){
        /*List<GoodsBrand> brandList = addressService.query("",null,-1,-1);
        List list = new ArrayList();
        for (GoodsBrand goodsBrand:brandList){
            Map map = new HashMap();
            map.put("gbid",goodsBrand.getId());
            map.put("gb_name",goodsBrand.getName());
            list.add(map);
        }*/
        return Result.ok();
    }


    @RequestMapping("/areaLst")
    public String areaLst(){
        List<Area> areaList = areaService.query(IAreaService.AREA_LIST,null,-1,-1);
        List list = new ArrayList();
        for (Area area:areaList){
            Map map = new HashMap();
            map.put("aid",area.getId());
            map.put("gb_name",area.getAreaName());

            if (area.getChilds().size()>0){
                map.put("children", AreaTools.ergodicChildren(area.getChilds()));
            }
            list.add(map);
        }
        return Result.ok(list);
    }


}
